package edu.neu.cs6515.net;

import java.io.IOException;
import java.net.Socket;
import java.net.SocketPermission;
import java.net.UnknownHostException;
import java.util.LinkedList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import edu.neu.cs6515.hci.HCIStrategy;
import edu.neu.cs6515.player.Player;
import edu.neu.cs6515.player.strategy.LowestColorFirstStrategy;
import edu.neu.cs6515.player.strategy.RandomStrategy;
import edu.neu.cs6515.player.strategy.StrategyException;
import edu.neu.cs6515.xml.IngeniousColor;
import edu.neu.cs6515.xml.Placement;
import edu.neu.cs6515.xml.Tile;
import edu.neu.cs6515.xml.w12.Accept;

/**
 * client of the distributed game
 */
public class Client {

    /**
     * run the client
     * 
     * @param player
     *            specify the name of the player
     * @param addr
     *            address of the server
     * @param port
     *            port of the server
     */
    public void runClient(final Player player, final String addr, final int port) {
        try {
            Socket sock = new Socket(addr, port);
            ProxySocketInOutput inOut = new ProxySocketInOutput(sock);
            AdministratorProxy adminProxy = new AdministratorProxy(inOut);
            adminProxy.registerPlayer(player.getPlayersName(), player);
        } catch (InputOutputException e) {
            System.out.println(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(final String[] args) {
        Player player = new Player(args[0], new LowestColorFirstStrategy());
        new Client().runClient(player, args[1], Integer.valueOf(args[2]));
    }
}
